<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$manage_op=array('confirm','cancel','agree','disagree');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择订单！','error');
	}
}
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'订单列表')
);
$workertitle=$this->setting['workertitle']?:'理发师';
$worktitle=$this->setting['worktitle']?:'理发';
$return['status']=array('0'=>'待消费','1'=>'服务中','2'=>'已完成','3'=>'已取消/过号');
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$data['uniacid']=$_SESSION['uniacid'];
	$data2['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['username'])){
		$data['realname like']='%'.trim($_RQ['username']).'%';
		$return['params']['username']=$_RQ['username'];
		$mid=pdo_getcolumn('core_members',$data,'id');
		if($mid){
			$params['user_id']=$mid;
		}
		
	}
	if(!empty($_RQ['worker_name'])){
		$data2['name like']='%'.trim($_RQ['worker_name']).'%';
		$return['params']['worker_name']=$_RQ['worker_name'];
		$wid=pdo_getcolumn('jy_meifa_worker',$data2,'id');
		if($wid){
			$params['wid']=$wid;
		}
		
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','sid','wid','user_id','money','pay','status','createtime');
	$list=pdo_getslice('jy_meifa_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['worker_name']=pdo_getcolumn('jy_meifa_worker',array('id'=>$item['wid'],'uniacid'=>$_SESSION['uniacid']),'name');
			$item['store_name']=pdo_getcolumn('jy_meifa_store',array('id'=>$item['sid'],'uniacid'=>$_SESSION['uniacid']),'title');
			$user=pdo_get('core_members',array('id'=>$item['user_id'],'uniacid'=>$_SESSION['uniacid']));
			$item['username']=$user['realname']?$user['realname']:'暂无';
			$item['nickname']=$user['nickname'];
			$item['user_mobile']=$user['mobile'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'nickname','title'=>'用户昵称','type'=>'string'),
			array('name'=>'username','title'=>'用户姓名','type'=>'string'),
			array('name'=>'worker_name','title'=>$workertitle.'姓名','type'=>'string'),
			array('name'=>'user_mobile','title'=>'用户电话','type'=>'string'),
			array('name'=>'store_name','title'=>'门店名称','type'=>'string'),
			array('name'=>'createtime','title'=>$worktitle.'时间','type'=>'time'),
			array('name'=>'money','title'=>'支付金额','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		)),
		'search'=>array(
			array('name'=>'username','title'=>'用户姓名','type'=>'string','width'=>'15'),
			array('name'=>'worker_name','title'=>$workertitle.'英文名','type'=>'string','width'=>'15'),
			array('name'=>'status','title'=>'订单状态','type'=>'select','options'=>'select_status','width'=>'15'),
		)
	);
	$return['select_status']=array(array('id'=>'0','title'=>'待消费'),array('id'=>'1','title'=>'服务中'),array('id'=>'2','title'=>'已完成'),array('id'=>'3','title'=>'已取消/过号'));
	$return['htmls']=$htmls;
	set_html('framess',$this->menu());
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_meifa_order',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
